package com.woniu.clientServer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.clientServer.dto.TransportationCompanyDto;
import com.woniu.clientServer.mapper.TransportationMethodMapper;
import com.woniu.clientServer.pojo.TransportationCompany;
import com.woniu.clientServer.pojo.TransportationMethod;
import com.woniu.clientServer.service.TransportationCompanyService;
import com.woniu.clientServer.mapper.TransportationCompanyMapper;
import com.woniu.clientServer.service.TransportationMethodService;
import com.woniu.common.utils.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 404
* @description 针对表【transportation_company】的数据库操作Service实现
* @createDate 2024-11-27 09:50:19
*/
@Service
public class TransportationCompanyServiceImpl extends ServiceImpl<TransportationCompanyMapper, TransportationCompany>
    implements TransportationCompanyService{
    @Autowired
    private TransportationMethodMapper methodMapper;

    @Override
    public ResponseData<?> queryAllM() {
        List<TransportationCompanyDto> companyDto = new ArrayList<>();
        List<TransportationCompany> company = lambdaQuery().list();
        for (TransportationCompany transportationCompany : company) {
            Integer id = transportationCompany.getId();
            TransportationCompanyDto transportationCompanyDto = new TransportationCompanyDto();
            transportationCompanyDto.setId(id);
            transportationCompanyDto.setTransportationName(transportationCompany.getTransportationName());
            transportationCompanyDto.setCode(transportationCompany.getCode());
            List<TransportationMethod> methods = methodMapper.queryByCode(transportationCompany.getCode());
            transportationCompanyDto.setTransportationMethods(methods);
            companyDto.add(transportationCompanyDto);
        }
        return new ResponseData<>().ok(companyDto);
    }
}




